package com.zhongwang.business.module.estimateBudgetAccountingManage.service;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhongwang.business.base.BaseService;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.AccountingInfoDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.EstimateDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.GetDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.SynchronizeDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.excelImport.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.redis.MatDescModel;
import com.zhongwang.business.util.FileUtils;
import com.zhongwang.business.util.ShiroUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 徐一贺
 * @className EstimateService 概算业务逻辑层
 * @description
 * @date 2020/12/11 16:37
 * @versron ver 1.0
 */
@Log4j2
@Service
public class EstimateService extends BaseService {
    @Autowired
    private SynchronizeDataDao syncDao;
    @Autowired
    private EstimateDao estimateDao;
    @Autowired
    private AccountingInfoDao accountingInfoDao;

    @Autowired
    private GetDataDao getDataDao;

    @Value("${user.upload.path}")
    private String uploadPath;

    /**
     * list 获取项目概算列表
     *
     * @param param 检索参数
     * @return List<AccountingProjectModel>
     * @author 徐一贺
     * @date 2020/12/11 16:54
     */
    public List<AccountingProjectModel> list(AccountingProjectModel param) {
        param.setCurrentUserId(ShiroUtils.getUserId());
        return estimateDao.findAccountingProjectListByCriteria(param);
    }

    /**
     * switchList 获取完成的核算列表
     *
     * @param param 检索参数
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.AccountingProjectModel>
     * @author 徐一贺
     * @date 2020/12/11 18:42
     */
    public List<AccountingProjectModel> switchList(AccountingProjectModel param) {
        return estimateDao.findAccountingProjectListByFinish(param);
    }

    /**
     * createEst
     * 创建概算
     * 1.创建单据表数据
     * 2.对对应任务ID修改状态
     * 2.获取样机清单数据
     * 3.获取样机明细数据 对明细数据处理
     * 处理公式：明细数量÷样机项目数量×概算项目数量
     *
     * @param param 概算信息
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/17 17:58
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult createEst(BusBudgetAccountingTaskModel param) {
        JsonResult jsonResult = new JsonResult();
        Date currentDate = new Date();
        try {
            //获取核算单据表
            BusBudgetAccountingTaskModel accountingTaskModel = estimateDao.getBusBudgetAccountingTaskByProCode(param.getReferenceProCode());
            BusBudgetAccountingTask estimateOrder = param;
            //获取该项目概算单据总数
            Integer orderCount = estimateDao.getBusBudgetAccountingTaskCountByProCode(estimateOrder.getProCode());
            estimateOrder.setSn(orderCount + 1);
            estimateOrder.setStartDate(currentDate);
            estimateOrder.setTaskUid(ShiroUtils.getUserId());
            estimateOrder.setTaskType(3);
            estimateOrder.setIsSave(0);
            estimateOrder.setDataStatus(1);
            estimateOrder.setMainParam(accountingTaskModel.getMainParam());
            estimateOrder.setPriceRangeDesignFlag(accountingTaskModel.getPriceRangeDesignFlag());
            estimateOrder.setPriceRangeMateriaFlag(accountingTaskModel.getPriceRangeMateriaFlag());
            estimateOrder.setPriceRangeManufactureFlag(accountingTaskModel.getPriceRangeManufactureFlag());
            estimateOrder.setPriceRangePackingFlag(accountingTaskModel.getPriceRangePackingFlag());
            estimateOrder.setPriceRangeTransportFlag(accountingTaskModel.getPriceRangeTransportFlag());
            estimateOrder.setPriceRangeInstall(accountingTaskModel.getPriceRangeInstall());
            estimateOrder.setPriceRangeInstallBusinessTravelSubsidyFlag(accountingTaskModel.getPriceRangeInstallBusinessTravelSubsidyFlag());
            estimateOrder.setPriceRangeInstallAccommodationFlag(accountingTaskModel.getPriceRangeInstallAccommodationFlag());
            estimateOrder.setPriceRangeInstallBusinessTravelFlag(accountingTaskModel.getPriceRangeInstallBusinessTravelFlag());
            estimateOrder.setPriceRangeInstallHoistingFlag(accountingTaskModel.getPriceRangeInstallHoistingFlag());
            estimateOrder.setPriceRangeDebugFlag(accountingTaskModel.getPriceRangeDebugFlag());
            estimateOrder.setPriceRangeSparePartsFlag(accountingTaskModel.getPriceRangeSparePartsFlag());
            estimateOrder.setPriceRangeTransportGuaranteeFlag(accountingTaskModel.getPriceRangeTransportGuaranteeFlag());
            estimateDao.insertBusBudgetAccountingTask(estimateOrder);
            //获取核算项目
            VwProject accountingProject = estimateDao.getVwProjectByCode(param.getReferenceProCode());
            //获取核算清单列表
            List<BusBudgetAccountingCostModel> accountingCostModelList = estimateDao.findBusBudgetAccountingCostByBatIdOrderById(accountingTaskModel.getId());
            //遍历插入概算清单列表
            for (int i = 0; i < accountingCostModelList.size(); i++) {
                BusBudgetAccountingCostModel item = accountingCostModelList.get(i);
                item.setBatId(estimateOrder.getId());
                item.setOrderNo(i + 1);
                item.setDataIden(1);
                if (item.getViewInfoFlag() == 1) {
                    item.setFinishStatus(1);
                }
                item.setIsEffectiveFlag(1);
                estimateDao.insertBusBudgetAccountingCost(item);
            }
            //获取概算清单列表
            List<BusBudgetAccountingCostModel> estCostModelList = estimateDao.findBusBudgetAccountingCostByBatId(estimateOrder.getId());
            //获取概算项目
            VwProject estProject = estimateDao.getVwProjectByCode(param.getProCode());
            //循环概算清单列表获取数据时同时把清单项主键写入数据中
            for (int i = 0; i < estCostModelList.size(); i++) {
                BusBudgetAccountingCostModel estCost = estCostModelList.get(i);
                String types = "";
                String laborTypes = "";
                if (estCost.getCode().contains("-材料费-材料采购费-")) {
                    String texture = estCost.getCode().substring(estCost.getCode().lastIndexOf("-") + 1);
                    //获取材料费数据即原材料
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            estCost.getId(),
                            texture,
                            "原材料",
                            null
                    );
                } else if (estCost.getCode().contains("-制造费-下料")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "7";
                        laborTypes = "4,5";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "8";
                        laborTypes = "4,5";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "9";
                        laborTypes = "4,5";
                    }
                    //获取下料数据
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-制造费-铆焊")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "13";
                        laborTypes = "6,7";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "14";
                        laborTypes = "6,7";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "15";
                        laborTypes = "6,7";
                    }
                    //获取铆焊数据
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-制造费-机加")) {
                    estimateDao.getBusMachiningHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-制造费-喷涂")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "25";
                        laborTypes = "9,10,11,12";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "26";
                        laborTypes = "9,10,11,12";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "27";
                        laborTypes = "9,10,11,12";
                    }
                    //获取喷涂数据
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-制造费-装配")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "31";
                        laborTypes = "13,14";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "32";
                        laborTypes = "13,14";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "33";
                        laborTypes = "13,14";
                    }
                    //获取装配数据
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-制造费-热处理")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "19";
                        laborTypes = "8";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "20";
                        laborTypes = "8";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "21";
                        laborTypes = "8";
                    }
                    //获取装配数据
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-外购费")) {
                    //获取材料费数据即外购件
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            estCost.getId(),
                            null,
                            "外购件",
                            null
                    );
                } else if (estCost.getCode().contains("-外协费-整体外协")) {
                    //获取材料费数据即外协件 整体外协
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            estCost.getId(),
                            null,
                            "外协件",
                            "'整体外协','铸件毛坯','锻件毛坯'"
                    );
                } else if (estCost.getCode().contains("-外协费-带料外协")) {
                    //获取材料费数据即外协件 带料外协
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            estCost.getId(),
                            null,
                            "外协件",
                            "'带料外协'"
                    );
                } else if (estCost.getCode().contains("-现场安装费-人工-安装人工")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "38";
                        laborTypes = "18";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "39";
                        laborTypes = "18";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "40";
                        laborTypes = "18";
                    }
                    //获取安装人工工时
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-现场安装费-人工-调试人工")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "1";
                        laborTypes = "20";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "2";
                        laborTypes = "20";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "3";
                        laborTypes = "20";
                    }
                    //获取调试人工工时
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-设计费")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "1";
                        laborTypes = "1,2,3";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "2";
                        laborTypes = "1,2,3";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "3";
                        laborTypes = "1,2,3";
                    }
                    //获取调试人工工时
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("-现场安装费-辅材")) {
                    if ("机械".equals(estCost.getMajor())) {
                        types = "38";
                        laborTypes = "19";
                    } else if ("流体".equals(estCost.getMajor())) {
                        types = "39";
                        laborTypes = "19";
                    } else if ("自动化".equals(estCost.getMajor())) {
                        types = "40";
                        laborTypes = "19";
                    }
                    //获取安装辅材
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            estCost.getMajor(),
                            estCost.getPart(),
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("包装运输费-包装费")) {
                    types = "34";
                    laborTypes = "15,16";
                    //获取包装工时和辅材
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            null,
                            null,
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("包装运输费-运输费")) {
                    types = "34";
                    laborTypes = "17";
                    //获取包装工时和辅材
                    estimateDao.getBusGeneralHours(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            null,
                            null,
                            types,
                            laborTypes,
                            estCost.getId()
                    );
                } else if (estCost.getCode().contains("备品备件")) {
                    //获取备品备件
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            null,
                            "备品备件",
                            estCost.getId(),
                            null,
                            "外购件",
                            null
                    );
                } else if (estCost.getCode().contains("随机备件")) {
                    //获取随机备件
                    estimateDao.getBusMaterialData(
                            accountingProject.getCode(),
                            accountingProject.getNum(),
                            estProject.getCode(),
                            estProject.getNum(),
                            estimateOrder.getId(),
                            accountingTaskModel.getId(),
                            null,
                            "随机备件",
                            estCost.getId(),
                            null,
                            "外购件",
                            null
                    );
                }
            }
            logService.saveLog("创建概算成本清单", "创建项目号为：【" + estProject.getCode() + "】,项目名称为：【" + estProject.getName() + "】的概算成本清单，概算名称为：【" + estimateOrder.getTitle() + "】。");
            //获取配置参数
            estimateDao.getBusBudgetAccountingBasicInfoConfig(estimateOrder.getId(), accountingTaskModel.getId());
            //生成概算数据
            oneClickBudgetEstimate(estimateOrder.getId());
            //获取任务反写任务状态
            Task task = estimateDao.getTaskByPrimaryKey(estimateOrder.getTaskId());
            task.setBegindate(currentDate);
            task.setTstatus(2);
            estimateDao.updateTaskByPrimaryKey(task);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setData(estimateOrder);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("创建概算异常：" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("创建概算失败！");
        }
        return jsonResult;
    }

    /**
     * oneClickBudgetEstimate 一键概算
     *
     * @param batId 概算单据表主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/22 9:43
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult oneClickBudgetEstimate(Integer batId) {
        JsonResult jsonResult = new JsonResult();
        Date currentDate = new Date();
        try {
            //获取单据表信息
            BusBudgetAccountingTaskModel order = estimateDao.getBusBudgetAccountingTaskByPrimaryKey(batId);
            //获取项目信息
            VwProjectModel project = estimateDao.getVwProjectByCode(order.getProCode());
            //获取税
            BusBudgetAccountingBasicInfoConfigModel taxConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "tax");
            BigDecimal tax = new BigDecimal(taxConfig.getValue()).divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP);
            //获取废料回收系数
            BusBudgetAccountingBasicInfoConfigModel wrcConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Coefficient of waste recovery");
            BigDecimal wrc = new BigDecimal(wrcConfig.getValue());
            //获取碳钢回收单价
            BusBudgetAccountingBasicInfoConfigModel csrupConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Carbon steel recovery");
            BigDecimal csrup = new BigDecimal(csrupConfig.getValue());
            //获取不锈钢回收单价
            BusBudgetAccountingBasicInfoConfigModel ssrupConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Stainless steel recycling");
            BigDecimal ssrup = new BigDecimal(ssrupConfig.getValue());
            //获取平均日工资
            BusBudgetAccountingBasicInfoConfigModel avgConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Average daily wage per capita of Zhongwang machinery");
            BigDecimal avg = new BigDecimal(avgConfig.getValue());
            //获取设计人均日工资
            BusBudgetAccountingBasicInfoConfigModel dsnConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Design per capita daily wage");
            BigDecimal dsn = new BigDecimal(dsnConfig.getValue());
            //获取现场安装人均日工资
            BusBudgetAccountingBasicInfoConfigModel installConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Per capita wage of site installation");
            BigDecimal ins = new BigDecimal(installConfig.getValue());
            //获取机加定额
            BusBudgetAccountingBasicInfoConfigModel macConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Machining quota");
            //获取管理费率
            BusBudgetAccountingBasicInfoConfigModel manConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "Management rate");
            BigDecimal man = new BigDecimal(manConfig.getValue());
            //获取运输费率
            BusBudgetAccountingBasicInfoConfigModel transportConfig = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(batId, "freight tax");
            BigDecimal transport = new BigDecimal(transportConfig.getValue()).divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP);
            //获取概算成本清单列表
            List<BusBudgetAccountingCostModel> costList = estimateDao.findBusBudgetAccountingCostByBatId(batId);
            Integer mode = new Integer(0);
            BigDecimal divisor = new BigDecimal(0);
            if (costList.size() > 0) {
                mode = costList.get(costList.size() - 1).getAmountDisplayModel().intValue();
                if (mode == 1) {
                    divisor = new BigDecimal(1);
                } else if (mode == 2) {
                    divisor = new BigDecimal(10000);
                } else if (mode == 3) {
                    divisor = new BigDecimal(1000000);
                } else if (mode == 4) {
                    divisor = new BigDecimal(100000000);
                }
            }
            for (BusBudgetAccountingCostModel cost : costList) {
                if(cost.getIsEffectiveFlag()==1){
                    if (cost.getCode().contains("-材料费-材料采购费") && "-材料采购费".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        BigDecimal costTotalPrice = new BigDecimal(0);
                        BigDecimal costTotalWeight = new BigDecimal(0);
                        BigDecimal wasteCostTotalWeight = new BigDecimal(0);
                        BigDecimal wasteCostTotalPrice = new BigDecimal(0);
                        //获取子集对子集进行概算算法与核算相同
                        List<BusBudgetAccountingCostModel> rawMatCostList = estimateDao.findBusBudgetAccountingCostModelByParentCode(cost);
                        for (BusBudgetAccountingCostModel rawMatCost : rawMatCostList) {
                            if(rawMatCost.getIsEffectiveFlag()==1){
                                if (!rawMatCost.getCode().contains("其他") && rawMatCost.getViewInfoFlag() == 1) {
                                    //获取总料重
                                    String dataType = "";
                                    if (rawMatCost.getCode().contains("-碳钢")) {
                                        dataType = "该项目材料费碳钢总料重";
                                    } else if (rawMatCost.getCode().contains("-不锈钢")) {
                                        dataType = "该项目材料费不锈钢总料重";
                                    } else if (rawMatCost.getCode().contains("-铝材")) {
                                        dataType = "该项目材料费铝材总料重";
                                    }
                                    //总料重吨
                                    BigDecimal totalWeight = estimateDao.getTotalWeightByCostId(rawMatCost.getId());
                                    BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                                    data.setDataType(dataType);
                                    if(totalWeight == null || totalWeight.compareTo(new BigDecimal(0))==0){
                                        data.setDataValue("0");
                                    }else{
                                        data.setDataValue(totalWeight.toString());
                                    }
                                    data.setDataUnit("吨");
                                    data.setUseType(3);
                                    data.setDataMajor(rawMatCost.getMajor());
                                    data.setDataPart(rawMatCost.getPart());
                                    data.setCostId(rawMatCost.getId());
                                    data.setBatId(rawMatCost.getBatId());
                                    data.setProCode(order.getProCode());
                                    saveBusBudgetAccountingEstimatesData(data);

                                    BusGeneralHoursModel netWeightCondition = new BusGeneralHoursModel();
                                    netWeightCondition.setBatId(rawMatCost.getBatId());
                                    if ("机械".equals(rawMatCost.getMajor())) {
                                        netWeightCondition.setTypes("1");
                                    } else if ("流体".equals(rawMatCost.getMajor())) {
                                        netWeightCondition.setTypes("2");
                                    } else if ("自动化".equals(rawMatCost.getMajor())) {
                                        netWeightCondition.setTypes("3");
                                    }
                                    //获取总净重
                                    if (rawMatCost.getCode().contains("-碳钢")) {
                                        dataType = "该项目材料费碳钢总净重";
                                        netWeightCondition.setLaborName("结构净重-碳钢");
                                    } else if (rawMatCost.getCode().contains("-不锈钢")) {
                                        dataType = "该项目材料费不锈钢总净重";
                                        netWeightCondition.setLaborName("结构净重-不锈钢");
                                    } else if (rawMatCost.getCode().contains("-铝材")) {
                                        dataType = "该项目材料费铝材总净重";
                                        netWeightCondition.setLaborName("结构净重-铝材");
                                    }
                                    netWeightCondition.setMajor(rawMatCost.getMajor());
                                    netWeightCondition.setPart(rawMatCost.getPart());
                                    netWeightCondition.setLaborTypes("2");
                                    //总净重吨
                                    BigDecimal totalNetWeight = estimateDao.getTotalNetWeightByCostId(netWeightCondition);
                                    if (totalNetWeight == null) {
                                        totalNetWeight = new BigDecimal(0);
                                    }
                                    data = new BusBudgetAccountingEstimatesData();
                                    data.setDataType(dataType);
                                    data.setDataValue(totalNetWeight.toString());
                                    data.setDataUnit("吨");
                                    data.setUseType(3);
                                    data.setDataMajor(rawMatCost.getMajor());
                                    data.setDataPart(rawMatCost.getPart());
                                    data.setCostId(rawMatCost.getId());
                                    data.setBatId(rawMatCost.getBatId());
                                    data.setProCode(order.getProCode());
                                    saveBusBudgetAccountingEstimatesData(data);
                                    //获取总价
                                    if (rawMatCost.getCode().contains("-碳钢")) {
                                        dataType = "该项目材料费碳钢总价";
                                    } else if (rawMatCost.getCode().contains("-不锈钢")) {
                                        dataType = "该项目材料费不锈钢总价";
                                    } else if (rawMatCost.getCode().contains("-铝材")) {
                                        dataType = "该项目材料费铝材总价";
                                    }
                                    //总价
                                    BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(rawMatCost.getId());
                                    totalPrice = totalPrice.subtract(totalPrice.multiply(tax));
                                    data = new BusBudgetAccountingEstimatesData();
                                    data.setDataType(dataType);
                                    data.setDataValue(estimateDao.getTotalPriceByCostId(rawMatCost.getId()).toString());
                                    data.setDataUnit("元");
                                    data.setUseType(3);
                                    data.setDataMajor(rawMatCost.getMajor());
                                    data.setDataPart(rawMatCost.getPart());
                                    data.setCostId(rawMatCost.getId());
                                    data.setBatId(rawMatCost.getBatId());
                                    data.setProCode(order.getProCode());
                                    saveBusBudgetAccountingEstimatesData(data);
                                    rawMatCost.setTotalPrice(totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP));

                                    if (totalWeight.compareTo(new BigDecimal(0)) == 1) {
                                        rawMatCost.setNum(totalWeight.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP));
                                        rawMatCost.setDisplayNum(rawMatCost.getNum().toString());
                                        rawMatCost.setPrice(totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP).divide(rawMatCost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                                    } else {
                                        rawMatCost.setNum(new BigDecimal(0));
                                        rawMatCost.setDisplayNum("0");
                                        rawMatCost.setPrice(new BigDecimal(0));
                                        rawMatCost.setDisplayPrice("0");
                                    }
                                    if (mode == 1) {
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                                        rawMatCost.setDisplayPrice(rawMatCost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                                    } else {
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                                        rawMatCost.setDisplayPrice(rawMatCost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                                    }
                                    String remark = "";
                                    if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                        if (totalWeight.compareTo(new BigDecimal(0)) == 1 && totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                            remark = "净重：" + totalNetWeight.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP).toString() + "吨，损耗:" + totalWeight.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP).subtract(totalNetWeight.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP)).divide(totalWeight.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP), 8, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%";
                                        } else {
                                            remark = "";
                                        }
                                        rawMatCost.setRemark(remark);
                                    }
                                    estimateDao.updateBusBudgetAccountingCostModel(rawMatCost);
                                    //获取对应的废料回收费
                                    rawMatCost.setCode(rawMatCost.getCode().replace("材料采购费", "废料回收费"));
                                    rawMatCost.setParentCode(rawMatCost.getParentCode().replace("材料采购费", "废料回收费"));
                                    BusBudgetAccountingCostModel wasteCost = estimateDao.getBusBudgetAccountingCostByWasteParam(rawMatCost);
                                    wasteCost.setNum(totalWeight.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP).subtract(totalNetWeight.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP)).multiply(wrc));
                                    wasteCostTotalWeight = wasteCostTotalWeight.add(wasteCost.getNum());
                                    wasteCost.setDisplayNum(wasteCost.getNum().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                                    if (rawMatCost.getCode().contains("-碳钢")) {
                                        wasteCost.setPrice(csrup);
                                    } else if (rawMatCost.getCode().contains("-不锈钢")) {
                                        wasteCost.setPrice(ssrup);
                                    } else if (rawMatCost.getCode().contains("-铝材")) {
                                        wasteCost.setPrice(rawMatCost.getPrice());
                                    }
                                    wasteCost.setTotalPrice(wasteCost.getNum().multiply(wasteCost.getPrice()));
                                    wasteCostTotalPrice = wasteCostTotalPrice.add(wasteCost.getTotalPrice());
                                    if (mode == 1) {
                                        rawMatCost.setDisplayPrice(rawMatCost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                                    } else {
                                        rawMatCost.setDisplayPrice(rawMatCost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                                    }
                                } else if (rawMatCost.getCode().contains("其他") && rawMatCost.getViewInfoFlag() == 1) {
                                    //获取总价
                                    String dataType = "该项目材料费其他总价";
                                    //总价
                                    BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(rawMatCost.getId());
                                    totalPrice = totalPrice.subtract(totalPrice.multiply(tax));
                                    BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                                    data.setDataType(dataType);
                                    data.setDataValue(estimateDao.getTotalPriceByCostId(rawMatCost.getId()).toString());
                                    data.setDataUnit("元");
                                    data.setUseType(3);
                                    data.setDataMajor(rawMatCost.getMajor());
                                    data.setDataPart(rawMatCost.getPart());
                                    data.setCostId(rawMatCost.getId());
                                    data.setBatId(rawMatCost.getBatId());
                                    data.setProCode(order.getProCode());
                                    saveBusBudgetAccountingEstimatesData(data);
                                    rawMatCost.setTotalPrice(totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                                    if (mode == 1) {
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                                    } else {
                                        rawMatCost.setDisplayTotalPrice(rawMatCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                                    }
                                    estimateDao.updateBusBudgetAccountingCostModel(rawMatCost);
                                }
                                if (rawMatCost.getNum() != null) {
                                    costTotalWeight = costTotalWeight.add(rawMatCost.getNum());
                                }
                                if (rawMatCost.getTotalPrice() != null) {
                                    costTotalPrice = costTotalPrice.add(rawMatCost.getTotalPrice());
                                }
                            }
                        }
                        cost.setTotalPrice(costTotalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        String remark = "材料总重：" + costTotalWeight.setScale(2, BigDecimal.ROUND_HALF_UP) + "吨";
                        cost.setRemark(remark);
                        cost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(cost));
                        if (mode == 1) {
                            cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        //获取对应的废料回收费总项
                        cost.setCode(cost.getCode().replace("材料采购费", "废料回收费"));
                        BusBudgetAccountingCostModel wasteCost = estimateDao.getBusBudgetAccountingCostByWasteParam(cost);
                        wasteCost.setNum(wasteCostTotalWeight);
                        wasteCost.setDisplayNum(wasteCostTotalWeight.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        if (wasteCost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            wasteCost.setRemark("废料总重：" + wasteCost.getDisplayNum() + "吨");
                        } else {
                            wasteCost.setRemark("");
                        }
                        wasteCost.setTotalPrice(wasteCostTotalPrice);
                        if (mode == 1) {
                            wasteCost.setDisplayTotalPrice(wasteCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            wasteCost.setDisplayTotalPrice(wasteCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        wasteCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(wasteCost));
                        if (mode == 1) {
                            wasteCost.setDisplayTrueAmount(wasteCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            wasteCost.setDisplayTrueAmount(wasteCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新废料回收费
                        estimateDao.updateBusBudgetAccountingCostModel(wasteCost);
                        //获取材料费成本项
                        BusBudgetAccountingCostModel matCost = estimateDao.getParentCostByCondition(wasteCost);
                        matCost.setTotalPrice(cost.getTotalPrice().subtract(wasteCost.getTotalPrice()));
                        if (mode == 1) {
                            matCost.setDisplayTotalPrice(matCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            matCost.setDisplayTotalPrice(matCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        matCost.setTrueAmount(cost.getTrueAmount().subtract(wasteCost.getTrueAmount()));
                        if (mode == 1) {
                            matCost.setDisplayTrueAmount(matCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            matCost.setDisplayTrueAmount(matCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新材料费
                        estimateDao.updateBusBudgetAccountingCostModel(matCost);
                    } else if (cost.getCode().contains("-制造费-下料") && "-下料".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取下料工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("7");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("8");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("9");
                        }
                        hoursCondition.setLaborTypes("4");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(avg);
                        hoursCondition.setLaborTypes("5");
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        //加上辅材成本
                        BigDecimal auxTotalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPrice = auxTotalPrice.subtract(auxTotalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        auxTotalPrice = auxTotalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        totalPrice = totalPrice.add(auxTotalPrice);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(totalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费下料总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费下料总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition)).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费下料不含税总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).subtract(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-制造费-铆焊") && "-铆焊".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取铆焊工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("13");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("14");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("15");
                        }
                        hoursCondition.setLaborTypes("6");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(avg);
                        hoursCondition.setLaborTypes("7");
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        //加上辅材成本
                        BigDecimal auxTotalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPrice = auxTotalPrice.subtract(auxTotalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        auxTotalPrice = auxTotalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        totalPrice = totalPrice.add(auxTotalPrice);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(totalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费铆焊总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费铆焊总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition)).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data.setDataType("该项目制造费铆焊不含税总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).subtract(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-制造费-机加") && "-机加".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取机加工时总成本
                        BigDecimal macTotalPrice = estimateDao.getMacTotalPrice(cost).divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        //总工时
                        List<BusMachiningHoursModel> macHoursList = estimateDao.findBusMachiningHoursByCondition(cost);
                        BigDecimal macTotalhours = new BigDecimal(0);
//                    for (BusMachiningHoursModel macHoursModel : macHoursList) {
//                        BigDecimal macHours = macHoursModel.getHours();
//                        //获取整数位
//                        BigDecimal macTotalhoursInteger = new BigDecimal(macTotalhours.toString().substring(0, macTotalhours.toString().indexOf(".")));
//                        BigDecimal macHoursInteger = new BigDecimal(macHours.toString().substring(0, macHours.toString().indexOf(".")));
//                        //获取小数位
//                        BigDecimal macTotalhoursDecimal = new BigDecimal(macTotalhours.toString().substring(macTotalhours.toString().indexOf(".") + 1)).divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP);
//                        BigDecimal macHoursDecimal = new BigDecimal(macHours.toString().substring(macHours.toString().indexOf(".") + 1)).divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP);
//                        if (macTotalhoursDecimal.add(macHoursDecimal).compareTo(new BigDecimal(0.6000)) == 1 || macTotalhoursDecimal.add(macHoursDecimal).compareTo(new BigDecimal(0.6000)) == 0) {
//                            macTotalhours = macTotalhoursInteger.add(macHoursInteger).add(new BigDecimal(1)).add(macTotalhoursDecimal.add(macHoursDecimal).subtract(new BigDecimal(0.6000)));
//                        } else {
//                            macTotalhours = macTotalhoursInteger.add(macHoursInteger).add(macTotalhoursDecimal.add(macHoursDecimal));
//                        }
//                    }
                        macTotalhours = estimateDao.getBusMachiningHoursByCondition(cost);
                        BigDecimal totalHours1 = new BigDecimal(0);
                        if (macTotalhours != null) {
                            totalHours1 = macTotalhours;
                            macTotalhours = macTotalhours.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        } else {
                            macTotalhours = new BigDecimal(0);
                        }
                        cost.setNum(macTotalhours.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                        cost.setDisplayNum(macTotalhours.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(macTotalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(macTotalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费机加总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费机加总价");
                        data.setDataValue(estimateDao.getMacTotalPrice(cost).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-制造费-喷涂") && cost.getCode().substring(cost.getCode().lastIndexOf("-")).equals("-喷涂")) {
                        //获取喷涂工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("25");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("26");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("27");
                        }
                        hoursCondition.setLaborTypes("9,11");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(avg);

                        hoursCondition.setLaborTypes("10,12");
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        //加上辅材成本
                        BigDecimal auxTotalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPrice = auxTotalPrice.subtract(auxTotalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        auxTotalPrice = auxTotalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        totalPrice = totalPrice.add(auxTotalPrice);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(totalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费喷涂总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费喷涂总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition)).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data.setDataType("该项目制造费喷涂不含税总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).subtract(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-制造费-装配") && "-装配".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取喷涂工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("31");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("32");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("33");
                        }
                        hoursCondition.setLaborTypes("13");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(avg);
                        hoursCondition.setLaborTypes("14");
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        //加上辅材成本
                        BigDecimal auxTotalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPrice = auxTotalPrice.subtract(auxTotalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        auxTotalPrice = auxTotalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        totalPrice = totalPrice.add(auxTotalPrice);

                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(totalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费装配总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费装配总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition)).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data.setDataType("该项目制造费装配不含税总价");
                        data.setDataValue(totalHours1.multiply(avg).add(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).subtract(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-制造费-热处理") && "-热处理".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取热处理工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("19");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("20");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("21");
                        }
                        hoursCondition.setLaborTypes("8");
                        BigDecimal totalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费热处理总价");
                        data.setDataValue(estimateDao.getAuxMatTotalPriceByCondition(hoursCondition).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        //获得父级更新父级制造费的成本项数据
                        BusBudgetAccountingCostModel manCost = estimateDao.getParentCostByCondition(cost);
                        BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(manCost);
                        manCost.setTotalPrice(manTotalPrice);
                        String remark = "";
                        //获取总净重
                        BigDecimal totalNetWeight = estimateDao.getTotalNetWeight(manCost).divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        BigDecimal tonPrice = new BigDecimal(0);
                        if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                            tonPrice = manTotalPrice.divide(totalNetWeight, 2, BigDecimal.ROUND_HALF_UP);
                        }
                        if (mode == 1) {
                            manCost.setDisplayTotalPrice(manCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            manCost.setManPrice(tonPrice.divide(divisor, 0, BigDecimal.ROUND_HALF_UP));
                            if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                remark = "制造单价：" + manCost.getManPrice() + "元/吨";
                            }
                        } else {
                            manCost.setDisplayTotalPrice(manCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            manCost.setManPrice(tonPrice.divide(divisor, 2, BigDecimal.ROUND_HALF_UP));
                            if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                remark = "制造单价：" + manCost.getManPrice() + "万元/吨";
                            }
                        }
                        manCost.setRemark(remark);
                        manCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(manCost));
                        if (mode == 1) {
                            manCost.setDisplayTrueAmount(manCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            manCost.setDisplayTrueAmount(manCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(manCost);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目制造费总价");
                        data.setDataValue(totalPrice.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(manCost.getMajor());
                        data.setDataPart(manCost.getPart());
                        data.setCostId(manCost.getId());
                        data.setBatId(manCost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-外购费") && "-外购费".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取外购费总成本
                        BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(cost.getId());
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目外购费总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目外购费不含税总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).subtract(estimateDao.getTotalPriceByCostId(cost.getId()).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-外协费-整体外协") && "-整体外协".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取整体外协总成本
                        BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(cost.getId());
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目整体外协总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目整体外协不含税总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).subtract(estimateDao.getTotalPriceByCostId(cost.getId()).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-外协费-带料外协") && "-带料外协".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取带料外协总成本
                        BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(cost.getId());
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目带料外协总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目带料外协不含税总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).subtract(estimateDao.getTotalPriceByCostId(cost.getId()).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        //获取父级外协费
                        //获得父级更新父级制造费的成本项数据
                        BusBudgetAccountingCostModel outCost = estimateDao.getParentCostByCondition(cost);
                        BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(outCost);
                        outCost.setTotalPrice(manTotalPrice);
                        if (mode == 1) {
                            outCost.setDisplayTotalPrice(outCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            outCost.setDisplayTotalPrice(outCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        outCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(outCost));
                        if (mode == 1) {
                            outCost.setDisplayTrueAmount(outCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            outCost.setDisplayTrueAmount(outCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(outCost);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目外协费总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(outCost.getMajor());
                        data.setDataPart(outCost.getPart());
                        data.setCostId(outCost.getId());
                        data.setBatId(outCost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-现场安装费-人工-安装人工") && "-安装人工".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取安装人工工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("38");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("39");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("40");
                        }
                        hoursCondition.setLaborTypes("18");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(ins);

                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        cost.setPrice(ins);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费人工安装人工总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费人工安装人工总价");
                        data.setDataValue(totalHours1.multiply(ins).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-现场安装费-人工-调试人工") && "-调试人工".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取调试人工工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("1");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("2");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("3");
                        }
                        hoursCondition.setLaborTypes("20");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalPrice1 = totalHours1.multiply(ins);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(ins);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        cost.setPrice(ins);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费人工调试人工总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费人工调试人工总价");
                        data.setDataValue(totalPrice1.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        //获取父级人工成本项
                        BusBudgetAccountingCostModel artificialCost = estimateDao.getParentCostByCondition(cost);
                        BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(artificialCost);
                        artificialCost.setTotalPrice(manTotalPrice);
                        if (mode == 1) {
                            artificialCost.setDisplayTotalPrice(artificialCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            artificialCost.setDisplayTotalPrice(artificialCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        artificialCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(artificialCost));
                        if (mode == 1) {
                            artificialCost.setDisplayTrueAmount(artificialCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            artificialCost.setDisplayTrueAmount(artificialCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(artificialCost);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目外协费总价");
                        data.setDataValue(totalPrice.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(artificialCost.getMajor());
                        data.setDataPart(artificialCost.getPart());
                        data.setCostId(artificialCost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-现场安装费-辅材") && "-辅材".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取安装辅材总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("38");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("39");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("40");
                        }
                        hoursCondition.setLaborTypes("19");
                        BigDecimal totalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        BigDecimal totalPrice1 = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费安装人工辅材总价");
                        data.setDataValue(totalPrice1.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目现场安装费安装人工辅材不含税总价");
                        data.setDataValue(totalPrice1.subtract(totalPrice1.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("-现场安装费-差旅") && "-差旅".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取父级现场安装调试费
                        BusBudgetAccountingCostModel installDebugCost = estimateDao.getParentCostByCondition(cost);
                        BigDecimal installDebugPrice = estimateDao.getChileTotalPrice(installDebugCost);
                        installDebugCost.setTotalPrice(installDebugPrice);
                        //获取总净重
                        BigDecimal totalNetWeight = estimateDao.getTotalNetWeight(installDebugCost).divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        BigDecimal tonPrice = new BigDecimal(0);
                        if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                            tonPrice = installDebugPrice.divide(totalNetWeight, 2, BigDecimal.ROUND_HALF_UP);
                        }
                        String remark = "";
                        if (mode == 1) {
                            installDebugCost.setDisplayTotalPrice(installDebugCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            installDebugCost.setInstallPrice(tonPrice.divide(divisor, 0, BigDecimal.ROUND_HALF_UP));
                            if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                remark = "安装单价：" + installDebugCost.getInstallPrice() + "元/吨";
                            }
                        } else {
                            installDebugCost.setDisplayTotalPrice(installDebugCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            installDebugCost.setInstallPrice(tonPrice.divide(divisor, 2, BigDecimal.ROUND_HALF_UP));
                            if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                                remark = "安装单价：" + installDebugCost.getInstallPrice() + "万元/吨";
                            }
                        }
                        installDebugCost.setRemark(remark);
                        installDebugCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(installDebugCost));
                        if (mode == 1) {
                            installDebugCost.setDisplayTrueAmount(installDebugCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            installDebugCost.setDisplayTrueAmount(installDebugCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(installDebugCost);
                    } else if (cost.getCode().contains("-设计费") && "-设计费".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取设计人工工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        if ("机械".equals(cost.getMajor())) {
                            hoursCondition.setTypes("1");
                        } else if ("流体".equals(cost.getMajor())) {
                            hoursCondition.setTypes("2");
                        } else if ("自动化".equals(cost.getMajor())) {
                            hoursCondition.setTypes("3");
                        }
                        hoursCondition.setLaborTypes("1");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(dsn);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        cost.setPrice(dsn);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目设计费总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目设计费总价");
                        data.setDataValue(totalHours1.multiply(dsn).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    }
                }
            }
            //统计各部分成本
            for (BusBudgetAccountingCostModel cost : costList) {
                if (cost.getIsEffectiveFlag()==1 && cost.getIsPart().intValue() == 1) {
                    BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(cost);
                    cost.setTotalPrice(manTotalPrice);
                    if (mode == 1) {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    cost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(cost));
                    if (mode == 1) {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    //更新成本信息
                    estimateDao.updateBusBudgetAccountingCostModel(cost);
                }
            }
            //统计各专业本
            for (BusBudgetAccountingCostModel cost : costList) {
                if (cost.getIsEffectiveFlag()==1 && cost.getIsMajor().intValue() == 1) {
                    BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(cost);
                    cost.setTotalPrice(manTotalPrice);
                    if (mode == 1) {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    cost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(cost));
                    if (mode == 1) {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    //更新成本信息
                    estimateDao.updateBusBudgetAccountingCostModel(cost);
                }
            }
            //统计小计成本
            for (BusBudgetAccountingCostModel cost : costList) {
                if (cost.getIsEffectiveFlag()==1 && "小计".equals(cost.getCode())) {
                    BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(cost);
                    cost.setTotalPrice(manTotalPrice);
                    if (mode == 1) {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    cost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(cost));
                    if (mode == 1) {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    //更新成本信息
                    estimateDao.updateBusBudgetAccountingCostModel(cost);
                }
            }
            //统计包装费、运输费、包装运输费、备品备件、随机备件、管理费成本
            for (BusBudgetAccountingCostModel cost : costList) {
                if(cost.getIsEffectiveFlag()==1){
                    if (cost.getCode().contains("包装运输费-包装费") && "-包装费".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        //获取包装工时总成本
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        hoursCondition.setTypes("34");
                        hoursCondition.setLaborTypes("15");
                        BigDecimal totalHours1 = estimateDao.getTotalHoursByCostId(hoursCondition);
                        BigDecimal totalHours = estimateDao.getTotalHoursByCostId(hoursCondition).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        BigDecimal totalPrice = totalHours.multiply(avg);
                        hoursCondition.setLaborTypes("16");
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP);
                        //加上辅材成本
                        BigDecimal auxTotalPrice = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPrice = auxTotalPrice.subtract(auxTotalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        auxTotalPrice = auxTotalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        totalPrice = totalPrice.add(auxTotalPrice);
                        cost.setNum(totalHours);
                        cost.setDisplayNum(totalHours.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setTotalPrice(totalPrice);
                        if (cost.getNum().compareTo(new BigDecimal(0)) == 1) {
                            cost.setPrice(totalPrice.divide(cost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                        } else {
                            cost.setPrice(new BigDecimal(0));
                        }
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                            cost.setDisplayPrice(cost.getPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目包装运输费包装总工时");
                        data.setDataValue(totalHours1.toString());
                        data.setDataUnit("工日");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目包装运输费包装总价");
                        data.setDataValue(totalPrice.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目包装运输费包装不含税总价");
                        BigDecimal auxTotalPriceNotHasTax = estimateDao.getAuxMatTotalPriceByCondition(hoursCondition);
                        auxTotalPriceNotHasTax = auxTotalPriceNotHasTax.subtract(auxTotalPriceNotHasTax.multiply(tax));
                        data.setDataValue(totalHours.multiply(avg).add(auxTotalPriceNotHasTax).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if (cost.getCode().contains("包装运输费-运输费") && "-运输费".equals(cost.getCode().substring(cost.getCode().lastIndexOf("-")))) {
                        BusGeneralHoursModel hoursCondition = new BusGeneralHoursModel();
                        hoursCondition.setCostId(cost.getId());
                        hoursCondition.setTypes("34");
                        hoursCondition.setLaborTypes("17");
                        BigDecimal totalPrice = estimateDao.getTotalTransportationExpensesByCostId(hoursCondition);

                        cost.setTotalPrice(totalPrice.divide(transport, 8, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目包装运输费运输费");
                        data.setDataValue(totalPrice.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目包装运输费运输费不含税");
                        totalPrice = totalPrice.divide(transport, 8, BigDecimal.ROUND_HALF_UP);
                        data.setDataValue(totalPrice.toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        //获取父级包装运输费
                        BusBudgetAccountingCostModel pacTranCost = estimateDao.getParentCostByCondition(cost);
                        BigDecimal pacTranPrice = estimateDao.getChileTotalPrice(pacTranCost);
                        pacTranCost.setTotalPrice(pacTranPrice);
                        if (mode == 1) {
                            pacTranCost.setDisplayTotalPrice(pacTranCost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            pacTranCost.setDisplayTotalPrice(pacTranCost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        pacTranCost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(pacTranCost));
                        if (mode == 1) {
                            pacTranCost.setDisplayTrueAmount(pacTranCost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            pacTranCost.setDisplayTrueAmount(pacTranCost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(pacTranCost);
                    } else if ("备品备件".equals(cost.getCode())) {
                        //获取备品备件总成本
                        BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(cost.getId());
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目备品备件总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目备品备件不含税总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).subtract(estimateDao.getTotalPriceByCostId(cost.getId()).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if ("随机备件".equals(cost.getCode())) {
                        //获取备品备件总成本
                        BigDecimal totalPrice = estimateDao.getTotalPriceByCostId(cost.getId());
                        totalPrice = totalPrice.subtract(totalPrice.multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        totalPrice = totalPrice.divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                        cost.setTotalPrice(totalPrice);
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                        BusBudgetAccountingEstimatesData data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目随机备件总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                        data = new BusBudgetAccountingEstimatesData();
                        data.setDataType("该项目随机备件不含税总价");
                        data.setDataValue(estimateDao.getTotalPriceByCostId(cost.getId()).subtract(estimateDao.getTotalPriceByCostId(cost.getId()).multiply(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))).toString());
                        data.setDataUnit("元");
                        data.setUseType(3);
                        data.setDataMajor(cost.getMajor());
                        data.setDataPart(cost.getPart());
                        data.setCostId(cost.getId());
                        data.setBatId(cost.getBatId());
                        data.setProCode(order.getProCode());
                        saveBusBudgetAccountingEstimatesData(data);
                    } else if ("管理费".equals(cost.getCode())) {
                        //获取小计
                        BusBudgetAccountingCost subtotalCondition = new BusBudgetAccountingCost();
                        subtotalCondition.setBatId(cost.getBatId());
                        subtotalCondition.setCode("小计");
                        BusBudgetAccountingCost subtotalCost = estimateDao.getBusBudgetAccountingCost(subtotalCondition);
                        cost.setTotalPrice(subtotalCost.getTotalPrice().multiply(man.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)));
                        if (mode == 1) {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        //更新成本信息
                        estimateDao.updateBusBudgetAccountingCostModel(cost);
                    }
                }
            }
            for (BusBudgetAccountingCostModel cost : costList) {
                if (cost.getIsEffectiveFlag()==1 && cost.getCode().equals("合计")) {
                    BigDecimal manTotalPrice = estimateDao.getChileTotalPrice(cost);
                    order.setAmount(manTotalPrice);
                    cost.setTotalPrice(manTotalPrice);
                    BigDecimal totalNetWeight = estimateDao.getTotalNetWeight(cost).divide(new BigDecimal(project.getNum()), 8, BigDecimal.ROUND_HALF_UP);
                    BigDecimal tonPrice = new BigDecimal(0);
                    if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                        tonPrice = manTotalPrice.divide(totalNetWeight, 2, BigDecimal.ROUND_HALF_UP);
                    }
                    String remark = "";
                    if (mode == 1) {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setInstallPrice(tonPrice.divide(divisor, 0, BigDecimal.ROUND_HALF_UP));
                        if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                            remark = "综合单价：" + cost.getInstallPrice() + "元/吨";
                        }
                    } else {
                        cost.setDisplayTotalPrice(cost.getTotalPrice().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                        cost.setInstallPrice(tonPrice.divide(divisor, 2, BigDecimal.ROUND_HALF_UP));
                        if (totalNetWeight.compareTo(new BigDecimal(0)) == 1) {
                            remark = "综合单价：" + cost.getInstallPrice() + "万元/吨";
                        }
                    }
                    cost.setTrueAmount(estimateDao.getTotalTrueAmountByParam(cost));
                    if (mode == 1) {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 0, BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        cost.setDisplayTrueAmount(cost.getTrueAmount().divide(divisor, 2, BigDecimal.ROUND_HALF_UP).toString());
                    }
                    cost.setRemark(remark);
                    //更新成本信息
                    estimateDao.updateBusBudgetAccountingCostModel(cost);
                }
            }
            //更新重量信息
            order.setEquipmentTotalWeight(estimateDao.getTotalWeightByBatId(batId));
            order.setEquipmentNetWeight(estimateDao.getTotalNetWeightByBatId(batId));
            estimateDao.updateBusBudgetAccountingTaskByPrimaryKey(order);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("一键概算成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("一键概算异常：" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("一键概算失败！");
        }
        return jsonResult;
    }

    /**
     * saveBusBudgetAccountingEstimatesData 保存数据
     *
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/22 14:19
     */
    private void saveBusBudgetAccountingEstimatesData(BusBudgetAccountingEstimatesData param) {
        BusBudgetAccountingEstimatesData model = estimateDao.getBusBudgetAccountingEstimatesDataByCondition(param);
        if (model != null) {
            param.setId(model.getId());
            estimateDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(param);
        } else {
            estimateDao.insertBusBudgetAccountingEstimatesData(param);
        }
    }


    /**
     * titleExist 验证该项下的概算名称是否重复
     *
     * @param param 项目号和title
     * @return java.lang.Boolean
     * @author 徐一贺
     * @date 2020/12/18 10:34
     */
    public Boolean titleExist(BusBudgetAccountingTaskModel param) {
        return estimateDao.getBusBudgetAccountingTaskByTitleAndProCode(param) == null;
    }

    /**
     * getVwProjectByCode 获取样机项目信息
     *
     * @param proCode 项目号
     * @return com.zhongwang.business.gen.entity.VwProject
     * @author 徐一贺
     * @date 2020/12/21 10:02
     */
    public VwProjectModel getVwProjectByCode(String proCode) {
        return estimateDao.getVwProjectByCode(proCode);
    }

    /**
     * getPrototypeAmountByProCode 根据项目号获取核算单据表信息
     *
     * @param proCode 项目号
     * @return java.math.BigDecimal
     * @author 徐一贺
     * @date 2020/12/21 10:05
     */
    public BigDecimal getPrototypeAmountByProCode(String proCode) {
        return estimateDao.getPrototypeAmountByProCode(proCode);
    }

    /**
     * checkCurrentDept 该概算是否是他部门的概算。是否是他的概算，是否有概算
     *
     * @param param 概算项目项目编号
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/21 16:20
     */
    public JsonResult checkCurrentDept(BusBudgetAccountingTaskModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            param.setCurrentUserId(ShiroUtils.getUserId());
            BusBudgetAccountingTaskModel checkModel = estimateDao.getChcekModel(param);
            if (checkModel.getIsSameDept() != 1) {
                jsonResult.setType(JsonResult.ResultType.ERROR);
                jsonResult.setMsg("尊敬的用户，此任务不是您所属部门的任务，故无法创建概算。");
                return jsonResult;
            } else {
                List<BusBudgetAccountingTaskModel> orderList = estimateDao.findBusBudgetAccountingTaskModelByProCode(param.getProCode());
                for (BusBudgetAccountingTaskModel model : orderList) {
                    if (model.getTaskUid().intValue() != ShiroUtils.getUserId()) {
                        jsonResult.setType(JsonResult.ResultType.ERROR);
                        jsonResult.setMsg("尊敬的用户，此任务已被他人创建概算，您无法创建。");
                        return jsonResult;
                    }
                }
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
        }
        return jsonResult;
    }

    /**
     * getProjectModelBybatId 根据单据表主键获取项目信息
     *
     * @param batId
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.ProjectModel
     * @throws
     * @author 徐一贺
     * @date 2020/12/21 18:05
     */
    public ProjectModel getProjectModelBybatId(Integer batId) {
        return estimateDao.getProjectModelBybatId(batId);
    }

    /**
     * getBusBudgetAccountingCostByPrimaryKey 根据主键获取成本项信息
     *
     * @param costId 成本项主键
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingCostModel
     * @author 徐一贺
     * @date 2020/12/22 7:56
     */
    public BusBudgetAccountingCostModel getBusBudgetAccountingCostByPrimaryKey(Integer costId) {
        return estimateDao.getBusBudgetAccountingCostByPrimaryKey(costId);
    }

    /**
     * getBusBudgetAccountingTaskByPrimaryKey 根据主键获取单据信息
     *
     * @param batId 单据主键
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingTaskModel
     * @author 徐一贺
     * @date 2020/12/22 8:04
     */
    public BusBudgetAccountingTaskModel getBusBudgetAccountingTaskByPrimaryKey(Integer batId) {
        return estimateDao.getBusBudgetAccountingTaskByPrimaryKey(batId);
    }

    /**
     * findSubmitList 加载概算待提交列表
     *
     * @param param 检索条件
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.AccountingProjectModel
     * 列表数据
     * @author 徐一贺
     * @date 2020/11/10 20:14
     * @version 1.0
     */
    public List<AccountingProjectModel> findSubmitList(AccountingProjectModel param) {
        param.setCurrentUserId(ShiroUtils.getUserId());
        return estimateDao.findSubmitList(param);
    }

    /**
     * saveOrder 保存概算清单
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/22 8:46
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult saveOrder(BusBudgetAccountingTask param) {
        JsonResult jsonResult = new JsonResult();
        try {
            param.setIsSave(1);
            estimateDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(param);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存概算清单成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("保存概算清单异常：" + ex.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存概算清单失败！");
        }
        return jsonResult;
    }

    /**
     * checkIsSave 检测概算是否保存过
     *
     * @param param 主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/22 9:10
     */
    public JsonResult checkIsSave(BusBudgetAccountingTask param) {
        JsonResult jsonResult = new JsonResult();
        if (estimateDao.getBusBudgetAccountingTaskByPrimaryKey(param.getId()).getIsSave() == 1) {
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("尊敬的用户，您的概算已保存！");
        } else {
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
        }
        return jsonResult;
    }

    /**
     * removeOrder 根据单据表主键删除概算
     *
     * @param param 单据表主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/23 11:12
     */
    public JsonResult removeOrder(BusBudgetAccountingTask param) {
        JsonResult result = new JsonResult();
        try {

            //获取单据信息
            BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(param.getId());
            //获取项目信息
            VwProject vwProject = getDataDao.getVwProjectByCode(busBudgetAccountingTask.getProCode());
            //清空任务信息
            Task task = getDataDao.getTaskByBatId(param.getId());
            if (busBudgetAccountingTask.getTaskType() == 2) {
                task.setTstatus(1);
                task.setBegindate(null);
                task.setEnddate(null);
                task.setKeyperson(null);
                task.setKeypersonid(null);
                getDataDao.updateTaskInfoByPrimaryKey(task);
            } else if (busBudgetAccountingTask.getTaskType() == 3) {
                Integer orderCount = getDataDao.getEstBusBudgetAccountingTaskCountByProCode(vwProject.getCode());
                if (orderCount == 1) {
                    task.setTstatus(1);
                    task.setBegindate(null);
                    task.setEnddate(null);
                    task.setKeyperson(null);
                    task.setKeypersonid(null);
                    getDataDao.updateTaskInfoByPrimaryKey(task);
                }
            }
            //删除数据源
            getDataDao.deleteBusBudgetDataSourceByBatId(param.getId());
            //删除核算清单相关数据
            getDataDao.deleteBusBudgetAccountingEstimatesDataByBatId(param.getId());
            //删除核算清单配置数据
            getDataDao.deleteBusBudgetAccountingBasicInfoConfigByBatId(param.getId());
            //删除核算清单表数据
            getDataDao.deleteBusBudgetAccountingCostByBatId(param.getId());
            //删除单据表信息
            getDataDao.deleteBusBudgetAccountTaskByBatId(param.getId());
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("删除概算成本清单成功！");
            logService.saveLog("删除概算成本清单", "删除项目号为：【" + vwProject.getCode() + "】,项目名称为：【" + vwProject.getName() + "】的概算成本清单。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("删除概算成本清单失败！");
        }
        return result;
    }

    /**
     * loadCostSheet 获取核算清单列表
     *
     * @param batId 单据表主键
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingCostModel>
     * @author 徐一贺
     * @date 2020/12/23 14:02
     */
    public List<BusBudgetAccountingCostModel> loadCostSheet(Integer batId) {
        return estimateDao.findBusBudgetAccountingCostListByBatIdAndVerId(batId);
    }

    /**
     * loadWeightParams 根据单据表主键获取重量参数
     *
     * @param batId 单据表主键
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.WeightParamModel
     * @author 徐一贺
     * @date 2020/12/7 16:35
     */
    public WeightParamModel loadWeightParams(Integer batId) {
        WeightParamModel resultParam = new WeightParamModel();
        BusBudgetAccountingTaskModel order = estimateDao.getBusBudgetAccountingTaskByPrimaryKey(batId);
        VwProject project = estimateDao.getVwProjectByCode(order.getProCode());
        resultParam.setWeight(estimateDao.getAccountingEquipmentTotalWeightByBatId(batId).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP));
        resultParam.setNetWeight(estimateDao.getAccountingEquipmentTotalNetWeightByBatId(batId).divide(new BigDecimal(project.getNum()), 2, BigDecimal.ROUND_HALF_UP));
        return resultParam;
    }

    /**
     * @className EstimateService
     * @description 数据有效无效操作
     * @author 徐一贺
     * @date 2020/12/24 9:21
     * @versron ver 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public int changeIsEffectiveFlagByMat(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusMaterialDataModel> datas = estimateDao.getBusMaterialDataModelByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMaterialDataModel data = datas.get(i);
                data.setIsEffectiveFlag(param.getIsEffectiveFlag());
                estimateDao.updateBusMaterialDataByPrimaryKeySelective(data);
                String content = "";
                if (param.getIsEffectiveFlag() == 1) {
                    content = "有效";
                } else {
                    content = "无效";
                }
                logService.saveLog("原材料数据状态修改", "物料描述为：【" + data.getMatDesc() + "】的数据状态修改为【" + content + "】");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("无效有效数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * changeIsEffectiveFlagByMan 数据有效无效操作
     *
     * @param param
     * @return int
     * @author 徐一贺
     * @date 2020/12/29 20:09
     */
    @Transactional(rollbackFor = Exception.class)
    public int changeIsEffectiveFlagByMan(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusGeneralHours> datas = estimateDao.getBusGeneralHoursByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusGeneralHours data = datas.get(i);
                data.setIsEffectiveFlag(param.getIsEffectiveFlag());
                estimateDao.updateBusGeneralHoursPrimaryKeySelective(data);
                String content = "";
                if (param.getIsEffectiveFlag() == 1) {
                    content = "有效";
                } else {
                    content = "无效";
                }
                logService.saveLog("制造费数据状态修改", "工时或辅材类别为：【" + data.getLaborName() + "】的数据状态修改为【" + content + "】");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("无效有效数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * changeIsEffectiveFlagByMac 机加数据有效无效操作
     *
     * @param param
     * @return int
     * @author 徐一贺
     * @date 2020/12/29 20:09
     */
    @Transactional(rollbackFor = Exception.class)
    public int changeIsEffectiveFlagByMac(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusMachiningHours> datas = estimateDao.getBusMachiningHoursByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMachiningHours data = datas.get(i);
                data.setIsEffectiveFlag(param.getIsEffectiveFlag());
                estimateDao.updateBusMachiningHoursPrimaryKeySelective(data);
                String content = "";
                if (param.getIsEffectiveFlag() == 1) {
                    content = "有效";
                } else {
                    content = "无效";
                }
                logService.saveLog("制造费数据状态修改", "机加工时设备型号：【" + data.getName() + "】的数据状态修改为【" + content + "】");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("无效有效数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * removeMat 根据主键们1删除原材料数据
     *
     * @param param 主键们
     * @return int
     * @author 徐一贺
     * @date 2020/12/24 10:06
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer removeMat(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusMaterialDataModel> datas = estimateDao.getBusMaterialDataModelByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMaterialDataModel data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() == null || data.getIsPrototypeDataFlag() != 1) {
                    BusBudgetAccountingCost cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(datas.get(i).getCostId());
                    estimateDao.deleteBusMaterialDataByPrimaryKey(data);
                    logService.saveLog("概算调整删除" + cost.getCode() + "数据", "物料描述为：【" + data.getMatDesc() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * removeMan 根据主键们删除工时辅材运费数据
     *
     * @param param
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/25 19:41
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer removeMan(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusGeneralHoursModel> datas = estimateDao.getBusGeneralHoursModelByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusGeneralHoursModel data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() == null || data.getIsPrototypeDataFlag() != 1) {
                    estimateDao.deleteBusGeneralHoursModelByPrimaryKey(data);
                    logService.saveLog("概算调整删除工时数据", "工时或辅材类型：【" + data.getLaborName() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除原材料数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    @Transactional(rollbackFor = Exception.class)
    public Integer removeMac(ChangeIsEffectiveFlagModel param) {
        try {
            List<BusMachiningHours> datas = estimateDao.getBusMachiningHoursByPrimaryKeys(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMachiningHours data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() == null || data.getIsPrototypeDataFlag() != 1) {
                    estimateDao.deleteBusMachiningHoursByPrimaryKey(data);
                    logService.saveLog("概算调整删除工时数据", "机加工时设备类型为：【" + data.getName() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除原材料数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * clearMat 根据成本项主键清空改成本项原材料数据
     *
     * @param param 成本项主键
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/24 12:55
     */
    public Integer clearMat(BusMaterialDataModel param) {
        try {
            List<BusMaterialDataModel> datas = estimateDao.getBusMaterialDataModelByCostId(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMaterialDataModel data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() != 1) {
                    estimateDao.deleteBusMaterialDataByPrimaryKey(data);
                    logService.saveLog("概算调整删除原材料数据", "物料描述为：【" + data.getMatDesc() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除原材料数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * clearMat 根据成本项主键清空改成本项工时辅材运费数据
     *
     * @param param 成本项主键
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/24 12:55
     */
    public Integer clearHours(BusMaterialDataModel param) {
        try {
            List<BusGeneralHoursModel> datas = estimateDao.getBusGeneralHoursModelByCostId(param);
            for (int i = 0; i < datas.size(); i++) {
                BusGeneralHoursModel data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() != 1) {
                    estimateDao.deleteBusGeneralHoursModelByPrimaryKey(data);
                    logService.saveLog("概算调整删除工时辅材运费数据", "工时辅材类型为：【" + data.getLaborName() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除制造费数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * clearMat 根据成本项主键清空改成本项工时辅材运费数据
     *
     * @param param 成本项主键
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/24 12:55
     */
    public Integer clearHoursMac(BusMaterialDataModel param) {
        try {
            List<BusMachiningHours> datas = estimateDao.getBusMachiningHoursModelByCostId(param);
            for (int i = 0; i < datas.size(); i++) {
                BusMachiningHours data = datas.get(i);
                if (data == null) {
                    return -1;
                }
                if (data.getIsPrototypeDataFlag() != 1) {
                    estimateDao.deleteBusMachiningHoursByPrimaryKey(data);
                    logService.saveLog("概算调整删除机加工时数据", "机加工时的设备类型为：【" + data.getName() + "】的数据被删除。");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整删除机加数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * rawMaterialList 获取原材料明细数据
     *
     * @param param
     * @return java.util.List<com.zhongwang.business.gen.entity.BusMaterialData>
     * @author 徐一贺
     * @date 2020/12/24 13:23
     */
    public List<BusMaterialData> rawMaterialList(BusMaterialData param) {
        return estimateDao.findRawMaterialList(param);
    }

    /**
     * matSaveAdd 添加材料数据
     *
     * @param data 数据
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/24 18:41
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer matSaveAdd(BusMaterialDataModel data) {
        try {
            data.setProCode(estimateDao.getBusBudgetAccountingTaskByPrimaryKey(data.getBatId()).getProCode());
            data.setUseType(3);
            estimateDao.matSaveAdd(data);
            logService.saveLog("概算调整添加原材料数据", "添加物料描述为：【" + data.getMatDesc() + "】的数据。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整添加原材料数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * wholeSaveAdd 添加整体外协
     *
     * @param data
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2021/1/4 12:59
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer wholeSaveAdd(BusMaterialDataModel data) {
        try {
            if (data.getId() == null) {
                data.setProCode(estimateDao.getBusBudgetAccountingTaskByPrimaryKey(data.getBatId()).getProCode());
                data.setUseType(3);
                estimateDao.matSaveAdd(data);
            } else {
                estimateDao.updateBusMaterialDataByPrimaryKeySelective(data);
            }
            logService.saveLog("概算调整保存整体外协数据", "添加物料描述为：【" + data.getMatDesc() + "】的数据。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整保存整体外协数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * whithMatSaveAdd 添加带料外协
     *
     * @param data
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2021/1/4 13:05
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer whithMatSaveAdd(BusMaterialDataModel data) {
        try {
            if (data.getId() == null) {
                data.setProCode(estimateDao.getBusBudgetAccountingTaskByPrimaryKey(data.getBatId()).getProCode());
                data.setUseType(3);
                estimateDao.matSaveAdd(data);
            } else {
                estimateDao.updateBusMaterialDataByPrimaryKeySelective(data);
            }
            logService.saveLog("概算调整保存带料外协数据", "添加物料描述为：【" + data.getMatDesc() + "】的数据。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("概算调整保存带料外协数据异常:" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * matExport 导出原材料数据 解决大批量数据无法导出的问题
     *
     * @param response
     * @param param
     * @author 徐一贺
     * @date 2020/12/24 19:07
     */
    public void matExport(HttpServletResponse response, BusMaterialDataModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<BusMaterialData> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportMatDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, RawMatExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * purExport 导出外购费样机数据
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/31 15:10
     */
    public void purExport(HttpServletResponse response, BusMaterialDataModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<PurExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportPurDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, PurExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectPurExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * wholeExport 整体外协导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 13:55
     */
    public void wholeExport(HttpServletResponse response, BusMaterialDataModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<WholeExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportWholeDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, WholeExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectWholeExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * withMatExport 带料外协列表
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 14:05
     */
    public void withMatExport(HttpServletResponse response, BusMaterialDataModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<WithMatExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportWithMatDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, WithMatExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectWithMatExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * aluExport 导出铝材样机数据
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/28 9:43
     */
    public void aluExport(HttpServletResponse response, BusMaterialDataModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<AluminiumExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportAluminumDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, AluminiumExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectAluminiumExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * cutExport 下料工时导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/26 8:25
     */
    public void cutExport(HttpServletResponse response, BusGeneralHoursModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("7");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("8");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("9");
        }
        param.setLaborTypes("4");
        List<CutExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportCutDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, CutExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectCutHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * rivetAndSolderExport 导出铆焊工时
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/28 8:33
     */
    public void rivetAndSolderExport(HttpServletResponse response, BusGeneralHoursModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("13");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("14");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("15");
        }
        param.setLaborTypes("6");
        List<RivetAndSolderExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportRivetAndSolderDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, RivetAndSolderExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectRivetAndSolderHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * sprayExport 导出喷涂样机工时数据
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/30 11:17
     */
    public void sprayExport(HttpServletResponse response, SprayExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("25");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("26");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("27");
        }
        param.setLaborTypes("9,11");
        List<SprayExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);

        //2.查询出数据导入到临时表
        estimateDao.createExportSprayDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, SprayExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectSprayHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * assemblyExport 导出装配工时
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/30 17:55
     */
    public void assemblyExport(HttpServletResponse response, AssemblyExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("31");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("32");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("33");
        }
        param.setLaborTypes("13");
        List<AssemblyExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportAssemblyDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, AssemblyExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectAssemblyHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * installExport 安装样机工时导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 18:34
     */
    public void installExport(HttpServletResponse response, InstallExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("38");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("39");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("40");
        }
        param.setLaborTypes("18");
        List<InstallExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportInstallDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, InstallExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectInstallHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * debugExport 导出调试工时
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 19:38
     */
    public void debugExport(HttpServletResponse response, DebugExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("1");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("2");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("3");
        }
        param.setLaborTypes("20");
        List<DebugExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportDebugDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, DebugExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectDebugHoursExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * designExport 设计工时导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/5 10:00
     */
    public void designExport(HttpServletResponse response, DesignExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("1");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("2");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("3");
        }
        param.setLaborTypes("1");
        List<DesignExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportDesignDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, DesignExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectDesignHoursExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * packingExport 包装工时导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/5 17:53
     */
    public void packingExport(HttpServletResponse response, PackingExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        param.setTypes("34");
        param.setLaborTypes("15");
        List<PackingExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportPackingDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, PackingExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectPackingHoursExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * packingAuxExport 包装辅材导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/5 18:01
     */
    public void packingAuxExport(HttpServletResponse response, PackingAuxExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        param.setTypes("34");
        param.setLaborTypes("16");
        List<PackingAuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportPackingAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, PackingAuxExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectPackingAuxExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * transportExport 运费导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/5 20:14
     */
    public void transportExport(HttpServletResponse response, TransportExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        param.setTypes("34");
        param.setLaborTypes("16");
        List<TransportExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportTransportDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-运费" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, TransportExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectTransportExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * designWeightExport 设计重量导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/5 10:15
     */
    public void designWeightExport(HttpServletResponse response, DesignWeightExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("1");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("2");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("3");
        }
        param.setLaborTypes("2,3");
        List<DesignWeightExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportDesignWeightDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-设计重量" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, DesignWeightExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectDesignWeightExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * auxExport 安装辅材导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 20:33
     */
    public void auxExport(HttpServletResponse response, AuxExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("38");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("39");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("40");
        }
        param.setLaborTypes("19");
        List<AuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, AuxExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectAuxExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * heatTreatmentExport 热处理重量导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/30 20:23
     */
    public void heatTreatmentExport(HttpServletResponse response, HeatTreatmentExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("31");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("32");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("33");
        }
        param.setLaborTypes("13");
        List<HeatTreatmentExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportHeatTreatmentDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-重量" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, HeatTreatmentExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectHeatTreatmentExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * assemblyAuxExport 装配辅材导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/30 20:22
     */
    public void assemblyAuxExport(HttpServletResponse response, AssemblyAuxExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(avg.getValue());
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("31");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("32");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("33");
        }
        param.setLaborTypes("14");
        List<AssemblyAuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportAssemblyAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, AssemblyAuxExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectAssemblyAuxExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * sprayAuxExport 导出喷涂样机辅材数据
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/30 13:00
     */
    public void sprayAuxExport(HttpServletResponse response, SprayAuxExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(avg.getValue());
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("25");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("26");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("27");
        }
        param.setLaborTypes("10,12");
        List<SprayAuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportSprayAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataAuxCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, SprayAuxExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectSprayAuxExportTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * macHoursExport 机加数据导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/29 20:49
     */
    public void macHoursExport(HttpServletResponse response, MacHoursExportModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        List<MacHoursExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportMacHoursDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-工时" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, MacHoursExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectBusMachiningHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * rivetAndSolderAuxExport 导出铆辅材
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/28 8:44
     */
    public void rivetAndSolderAuxExport(HttpServletResponse response, BusGeneralHoursModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingBasicInfoConfig avg = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(cost.getBatId(), "Average daily wage per capita of Zhongwang machinery");
        param.setPrice(new BigDecimal(avg.getValue()));
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("13");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("14");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("15");
        }
        param.setLaborTypes("7");
        List<RivetAndSolderAuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportRivetAndSolderAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, RivetAndSolderAuxImportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectRivetAndSolderAuxHoursExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * cutExport 下料辅材导出
     *
     * @param response
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/26 8:25
     */
    public void cutAuxExport(HttpServletResponse response, BusGeneralHoursModel param) {
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        if ("机械".equals(cost.getMajor())) {
            param.setTypes("7");
        } else if ("流体".equals(cost.getMajor())) {
            param.setTypes("8");
        } else if ("自动化".equals(cost.getMajor())) {
            param.setTypes("9");
        }
        param.setLaborTypes("5");
        List<CutAuxExportModel> list = new ArrayList<>();
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        //1.创建临时内存表名
        String tempTableName = "##" + ShiroUtils.getUser().getAccount() + (UUID.randomUUID().toString().replace("-", ""));
        param.setTempTableName(tempTableName);
        //2.查询出数据导入到临时表
        estimateDao.createExportCutAuxDataTempTable(param);
        //3.查询临时内存表数据导出
        Integer dataCount = estimateDao.getTempTableDataCount(param);
        int step = 5000;
        FileUtils.mkdirs(path);
        // 方法1 如果写到同一个sheet
        path = path + cost.getCode() + "-辅材" + ".xlsx";
        ExcelWriter excelWriter = null;
        try {
            // 这里 需要指定写用哪个class去写
            excelWriter = EasyExcel.write(path, CutAuxExportModel.class).build();
            // 这里注意 如果同一个sheet只要创建一次
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
            for (int topCount = 5000, notHaveTopCount = 0; notHaveTopCount < dataCount; notHaveTopCount += step) {
                param.setTopCount(topCount);
                param.setNotHaveTopCount(notHaveTopCount);
                list = estimateDao.selectCutAuxExportDeferralTempTableData(param);
                if (list != null) {
                    excelWriter.write(list, writeSheet);
                }
            }
            //4.删除临时内存表
            estimateDao.dropExportTempTable(tempTableName);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        //5.下载
        FileUtils.downloadFile(path, response);
    }

    /**
     * getRawMatAmount 获取原材料金额
     *
     * @param param id 成本项主键
     * @return java.util.Map<java.lang.String, java.lang.Object> 结果
     * @author 徐一贺
     * @date 2020/12/25 9:33
     */
    public Map<String, Object> getRawMatAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        BusBudgetAccountingTaskModel order = estimateDao.getBusBudgetAccountingTaskByPrimaryKey(cost.getBatId());
        BusBudgetAccountingBasicInfoConfigModel taxModel = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(order.getId(), "tax");
        String dataType = "";
        if (cost.getCode().contains("-碳钢")) {
            dataType = "该项目材料费碳钢总价";
        } else if (cost.getCode().contains("-不锈钢")) {
            dataType = "该项目材料费不锈钢总价";
        } else if (cost.getCode().contains("-铝材")) {
            dataType = "该项目材料费铝材总价";
        } else if (cost.getCode().contains("-其他")) {
            dataType = "该项目材料费其他总价";
        }
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BigDecimal amountTax = new BigDecimal(estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue());
        resultMap.put("amount", amountTax.subtract(amountTax.multiply(new BigDecimal(taxModel.getValue()).divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP))));
        resultMap.put("amountTax", amountTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getCutAmount 获取工时辅材等金额数据
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2020/12/25 20:52
     */
    public Map<String, Object> getCutAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        if (cost.getCode().contains("-下料")) {
            dataType = "该项目制造费下料总价";
        } else if (cost.getCode().contains("-铆焊")) {
            dataType = "该项目制造费铆焊总价";
        } else if (cost.getCode().contains("-机加")) {
            dataType = "该项目制造费机加总价";
        } else if (cost.getCode().contains("-喷涂")) {
            dataType = "该项目制造费喷涂总价";
        } else if (cost.getCode().contains("-装配")) {
            dataType = "该项目制造费装配总价";
        } else if (cost.getCode().contains("-热处理")) {
            dataType = "该项目制造费热处理总价";
        } else if (cost.getCode().contains("包装运输费-包装费")) {
            dataType = "该项目包装运输费包装总价";
        }
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        if (cost.getCode().contains("-下料")) {
            dataType = "该项目制造费下料不含税总价";
        } else if (cost.getCode().contains("-铆焊")) {
            dataType = "该项目制造费铆焊不含税总价";
        } else if (cost.getCode().contains("-喷涂")) {
            dataType = "该项目制造费喷涂不含税总价";
        } else if (cost.getCode().contains("-装配")) {
            dataType = "该项目制造费装配不含税总价";
        } else if (cost.getCode().contains("包装运输费-包装费")) {
            dataType = "该项目包装运输费包装不含税总价";
        }
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getPurAmount 获取外购费金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2020/12/31 9:04
     */
    public Map<String, Object> getPurAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        if (cost.getCode().contains("-外购费")) {
            dataType = "该项目外购费总价";
        }
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        if (cost.getCode().contains("-外购费")) {
            dataType = "该项目外购费不含税总价";
        }
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getWholeAmount 获取整体外协金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2020/12/31 9:04
     */
    public Map<String, Object> getWholeAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目整体外协总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目整体外协不含税总价";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getWithMatAmount 获取带料外协金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2020/12/31 9:04
     */
    public Map<String, Object> getWithMatAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目带料外协总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目带料外协不含税总价";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getInstallAux 获取安装辅材总监
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/4 15:44
     */
    public Map<String, Object> getInstallAux(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目现场安装费安装人工辅材总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目现场安装费安装人工辅材不含税总价";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getSparePartsAmount 获取备品备件总金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/6 9:49
     */
    public Map<String, Object> getSparePartsAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目备品备件总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目备品备件不含税总价";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getAccompanyingSparePartsAmount 获取随机备件总金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/6 9:49
     */
    public Map<String, Object> getAccompanyingSparePartsAmount(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目随机备件总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目随机备件不含税总价";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getTransportCostTotalPrice 获取运输金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/5 19:24
     */
    public Map<String, Object> getTransportCostTotalPrice(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目包装运输费运输费";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountTax = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amountTax = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amountTax", amountTax);
        dataType = "该项目包装运输费运输费不含税";
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountNotTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amountNotTax = new BigDecimal(0);
        if (amountNotTaxObj != null) {
            String amountNotTaxStr = amountNotTaxObj.getDataValue();
            if (amountNotTaxStr != null) {
                amountNotTax = new BigDecimal(amountNotTaxStr);
            }
        }
        resultMap.put("amount", amountNotTax);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getDesignCostTotalPrice 获取设计费成本项金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/5 8:24
     */
    public Map<String, Object> getDesignCostTotalPrice(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getInstallArtificial 获取安装人工金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/4 15:40
     */
    public Map<String, Object> getInstallArtificial(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目现场安装费人工安装人工总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amount = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amount = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amount", amount);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getDebugArtificial 获取调试人工金额
     *
     * @param param
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author 徐一贺
     * @date 2021/1/4 15:40
     */
    public Map<String, Object> getDebugArtificial(BusBudgetAccountingCostModel param) {
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingCostModel cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        String dataType = "";
        dataType = "该项目现场安装费人工调试人工总价";
        BusBudgetAccountingEstimatesData dataParam = new BusBudgetAccountingEstimatesData();
        dataParam.setCostId(cost.getId());
        dataParam.setDataType(dataType);
        BusBudgetAccountingEstimatesData amountTaxObj = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam);
        BigDecimal amount = new BigDecimal(0);
        if (amountTaxObj != null) {
            String amountTaxStr = estimateDao.getBusBudgetAccountingEstimatesDataByCostIdAndDataType(dataParam).getDataValue();
            if (amountTaxStr != null) {
                amount = new BigDecimal(amountTaxStr);
            }
        }
        resultMap.put("amount", amount);
        resultMap.put("costTotalPrice", cost.getTotalPrice());
        return resultMap;
    }

    /**
     * getBusBudgetAccountingCostModelByPrimaryKey 根据主键获取成本项
     *
     * @param id 主键
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingCostModel
     * @author 徐一贺
     * @date 2020/12/25 10:46
     */
    public BusBudgetAccountingCostModel getBusBudgetAccountingCostModelByPrimaryKey(Integer id) {
        return estimateDao.getBusBudgetAccountingCostByPrimaryKey(id);
    }

    /**
     * findBusMachiningHoursModellListByCondition
     * 根据条件获取机加明细列表
     *
     * @param macCondition 条件
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMachiningHoursModel>
     * @author 徐一贺
     * @date 2020/11/7 7:57
     */
    public List<BusMachiningHoursModel> findBusMachiningHoursModelListByCondition(BusMachiningHoursModel macCondition) {
        return estimateDao.findBusMachiningHoursModelListByCondition(macCondition);
    }

    /**
     * findBusGeneralHoursModelListByCondition 根据条件获取数据
     *
     * @param condition
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusGeneralHoursModel>
     * @author 徐一贺
     * @date 2020/12/25 10:56
     */
    public List<BusGeneralHoursModel> findBusGeneralHoursModelListByCondition(BusGeneralHoursModel condition) {
        return estimateDao.findBusGeneralHoursModelListByCondition(condition);
    }

    /**
     * cutHoursSaveAdd 添加工时 辅材 运费数据
     *
     * @param param 数据
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/25 19:21
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult cutHoursSaveAdd(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getCostId());
            if (cost.getCode().contains("-制造费-下料")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(7);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(8);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(9);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(4);
                } else if ("辅材".equals(param.getDataType())) {
                    param.setLaborType(5);
                }
            } else if (cost.getCode().contains("-制造费-铆焊")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(13);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(14);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(15);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(6);
                } else if ("辅材".equals(param.getDataType())) {
                    param.setLaborType(7);
                }
            } else if (cost.getCode().contains("-制造费-喷涂")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(25);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(26);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(27);
                }
                if ("工时".equals(param.getDataType())) {
                    if ("喷砂处理".equals(param.getSprayType())) {
                        param.setLaborType(9);
                    } else if ("涂装处理".equals(param.getSprayType())) {
                        param.setLaborType(11);
                    }
                } else if ("辅材".equals(param.getDataType())) {
                    if ("喷砂处理".equals(param.getSprayType())) {
                        param.setLaborType(10);
                    } else if ("涂装处理".equals(param.getSprayType())) {
                        param.setLaborType(12);
                    }
                }
            } else if (cost.getCode().contains("-制造费-装配")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(31);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(32);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(33);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(13);
                } else if ("辅材".equals(param.getDataType())) {
                    param.setLaborType(14);
                }
            } else if (cost.getCode().contains("-制造费-热处理")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(19);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(20);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(21);
                }
                if ("重量".equals(param.getDataType())) {
                    param.setLaborType(8);
                }
            } else if (cost.getCode().contains("-现场安装费-人工-安装人工")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(38);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(39);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(40);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(18);
                }
            } else if (cost.getCode().contains("-现场安装费-人工-调试人工")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(1);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(2);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(3);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(20);
                }
            } else if (cost.getCode().contains("-现场安装费-辅材")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(38);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(39);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(40);
                }
                if ("辅材".equals(param.getDataType())) {
                    param.setLaborType(19);
                }
            } else if (cost.getCode().contains("-设计费")) {
                if ("机械".equals(cost.getMajor())) {
                    param.setType(1);
                } else if ("流体".equals(cost.getMajor())) {
                    param.setType(2);
                } else if ("自动化".equals(cost.getMajor())) {
                    param.setType(3);
                }
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(1);
                }
            } else if (cost.getCode().contains("包装运输费-包装费")) {
                param.setType(34);
                if ("工时".equals(param.getDataType())) {
                    param.setLaborType(15);
                } else if ("辅材".equals(param.getDataType())) {
                    param.setLaborType(16);
                }
            } else if (cost.getCode().contains("包装运输费-运输费")) {
                param.setType(34);
                param.setLaborType(17);
            }
            estimateDao.insertBusGeneralHours(param);
            logService.saveLog("概算调整", "添加了一条" + cost.getCode() + "数据。");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加工时辅材运费数据时异常：" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("添加失败！");
        }
        return jsonResult;
    }

    /**
     * auxSaveUpdate 更新现场安装辅材
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/4 20:26
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult auxSaveUpdate(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getCostId());
            estimateDao.updateBusGeneralHoursPrimaryKeySelective(param);
            logService.saveLog("概算调整", "新更新了一条" + cost.getCode() + "数据。");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("更新成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("更新工时辅材运费数据时异常：" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("更新失败！");
        }
        return jsonResult;
    }

    /**
     * updateTransportSave 更新运输费
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/5 19:58
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updateTransportSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost = estimateDao.getBusBudgetAccountingCostByPrimaryKey(param.getCostId());
            estimateDao.updateBusGeneralHoursPrimaryKeySelective(param);
            logService.saveLog("概算调整", "新更新了一条" + cost.getCode() + "数据。");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("更新成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("更新工时辅材运费数据时异常：" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("更新失败！");
        }
        return jsonResult;
    }

    /**
     * findBusMachiningHoursModelListByEstCondition 获得机加工时列表
     *
     * @param macCondition
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMachiningHoursModel>
     * @author 徐一贺
     * @date 2020/12/29 10:40
     */
    public List<BusMachiningHoursModel> findBusMachiningHoursModelListByEstCondition(BusMachiningHoursModel macCondition) {
        return estimateDao.findBusMachiningHoursModelListByEstCondition(macCondition);

    }

    /**
     * getResultMacHours 获取机加计算结果
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/29 11:27
     */
    public BigDecimal getResultMacHours(GetResultMacHoursModel param) {
        return estimateDao.getResultMacHours(param);
    }

    /**
     * loadProcessList 加载工序列表
     *
     * @param
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.VwComProcessModel>
     * @author 徐一贺
     * @date 2020/12/29 16:35
     */
    public List<VwComProcessModel> loadProcessList() {
        return estimateDao.findProcessList();
    }

    /**
     * loadNameTypeList 获取设备类型列表
     *
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.VwEquTypeModel>
     * @author 徐一贺
     * @date 2020/12/29 16:53
     */
    public List<VwEquTypeModel> loadNameTypeList() {
        return estimateDao.findNameTypeList();
    }

    /**
     * loadNameList 根据设备类型获取设备列表
     *
     * @param nameType 设备类型
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.VwEquModel>
     * @author 徐一贺
     * @date 2020/12/29 17:46
     */
    public List<VwEquModel> loadNameList(String nameType) {
        return estimateDao.findNameList(nameType);
    }

    /**
     * macSaveAdd 添加机加工时
     *
     * @param param 机加工时
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/29 18:58
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer macSaveAdd(BusMachiningHoursModel param) {
        param.setIsEffectiveFlag(1);
        param.setIsPrototypeDataFlag(0);
        try {
            //获取当前定额
            BusBudgetAccountingBasicInfoConfigModel macQuota = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(param.getBatId(), "Machining quota");
            param.setBmeVersion(macQuota.getValue());
            BusMachiningEquipment condition = new BusMachiningEquipment();
            condition.setVersion(macQuota.getValue());
            condition.setName(param.getName());
            condition.setNameType(param.getNameType());
            BusMachiningEquipment busMachiningEquipment = estimateDao.getBusMachiningEquipmentByCondition(condition);
            param.setPrice(busMachiningEquipment.getPrice());
            param.setHours(new BigDecimal(param.getWorkHoursStr() + "." + param.getWorkMinuteStr()));
            estimateDao.insertBusMachiningHours(param);
            logService.saveLog("概算调整-机加工时明细", "添加机加工时,设备名称是【" + param.getName() + "】。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("添加加工时异常：" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * macSaveEdit 编辑机加工时
     *
     * @param param
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/29 19:55
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer macSaveEdit(BusMachiningHoursModel param) {
        param.setIsEffectiveFlag(1);
        param.setIsPrototypeDataFlag(0);
        try {
            //获取当前定额
            BusBudgetAccountingBasicInfoConfigModel macQuota = estimateDao.getBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(param.getBatId(), "Machining quota");
            param.setBmeVersion(macQuota.getValue());
            BusMachiningEquipment condition = new BusMachiningEquipment();
            condition.setVersion(macQuota.getValue());
            condition.setName(param.getName());
            condition.setNameType(param.getNameType());
            BusMachiningEquipment busMachiningEquipment = estimateDao.getBusMachiningEquipmentByCondition(condition);
            param.setPrice(busMachiningEquipment.getPrice());
            param.setHours(new BigDecimal(param.getWorkHoursStr() + "." + param.getWorkMinuteStr()));
            estimateDao.updateBusMachiningHoursByPrimaryKeySelective(param);
            logService.saveLog("概算调整-机加工时明细", "编辑机加工时,设备名称是【" + param.getName() + "】。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("添加加工时异常：" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * spraySave 保存喷涂信息
     *
     * @param param
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2020/12/30 14:08
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer spraySave(BusGeneralHoursModel param) {
        param.setIsEffectiveFlag(1);
        param.setIsPrototypeDataFlag(0);
        try {
            estimateDao.updateBusGeneralHoursPrimaryKeySelective(param);
            logService.saveLog("概算调整-喷涂工时明细", "保存编辑喷涂成功。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("保存编辑喷涂时异常：" + ex.getMessage());
            return 0;
        }
        return 1;
    }

    /**
     * purList 获取外购件列表
     *
     * @param param
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMaterialDataModel>
     * @author 徐一贺
     * @date 2020/12/31 8:33
     */
    public List<BusMaterialDataModel> purList(BusMaterialDataModel param) {
        return estimateDao.purList(param);
    }

    /**
     * wholeList 获取整体外协列表
     *
     * @param param
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMaterialDataModel>
     * @author 徐一贺
     * @date 2021/1/4 12:39
     */
    public List<BusMaterialDataModel> wholeList(BusMaterialDataModel param) {
        return estimateDao.wholeList(param);
    }

    /**
     * whishMatList 获取带料外协列表
     *
     * @param param
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMaterialDataModel>
     * @author 徐一贺
     * @date 2021/1/4 12:47
     */
    public List<BusMaterialDataModel> whishMatList(BusMaterialDataModel param) {
        return estimateDao.whishMatList(param);
    }

    /**
     * findMatDescList 获取提包描述下拉框
     *
     * @return java.lang.Object
     * @author 徐一贺
     * @date 2020/12/31 12:46
     */
    public List<MatDescModel> findMatDescList(int topCount, String keyStr) {
        return estimateDao.findMatDescList(topCount, keyStr);
    }

    /**
     * purSave 添加或保存编辑外购费
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/31 14:34
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult purSave(BusMaterialDataModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            if (param.getId() != null) {
                estimateDao.updateBusMaterialDataByPrimaryKeySelective(param);
                logService.saveLog("概算调整-外购件明细", "保存编辑提报计划物料描述：【" + param.getMatDesc() + "】的外购件成功。");
            } else {
                estimateDao.insertBusMaterialData(param);
                logService.saveLog("概算调整-外购件明细", "添加提报计划物料描述：【" + param.getMatDesc() + "】的外购件成功。");
            }
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("操作成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("保存编辑外购费时异常：" + ex.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("操作失败！");
        }
        return jsonResult;
    }

    /**
     * updateInstallHoursSave 更新安装工时
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/4 18:13
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updateInstallHoursSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算调整-保存安装工时", "安装工时类别为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * updatePackingHoursSave 更新打包工时
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/5 16:50
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updatePackingHoursSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算调整-保存打包工时", "打包工时类别为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * updatePackingAuxSave 更新打包辅材
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/5 17:46
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updatePackingAuxSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算调整-保存打包辅材", "打包辅材类别为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * updateDebugHoursSave 更新调试工时
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/4 18:13
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updateDebugHoursSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算调整-保存调试工时", "调试工时类别为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * updateDsnHoursSave 更新设计工时
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/5 8:58
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult updateDsnHoursSave(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算调整-保存设计工时", "设计工时类别为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * findApprovalList 获取概算成本清单提审核表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/25 8:47
     * @version 1.0
     */
    public List<AccountingProjectModel> findApprovalList(AccountingProjectModel param) {
        param.setCurrentUserId(ShiroUtils.getUserId());
        return estimateDao.findApprovalList(param);
    }


    /**  estimatingApproval 概算审核
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/8 10:41
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult estimatingApproval(AccountingProjectModel param) {
        JsonResult jsonResult = new JsonResult();
        Date currentTime = new Date();
        try {
            //获取单据表信息
            BusBudgetAccountingTaskModel order = getDataDao.getBusBudgetAccountingTaskModelByVerifyProcessPrimarykey(param.getId());
            param.setAppTime(currentTime);
            getDataDao.updVerifyProcess(param);
            //根据当前的节点，OK NG+意见
            //1·OK
            AccountingProjectModel nowProcess = getDataDao.findVerifyProcess(param.getId());
            //获取审核级别
            AccountingProjectModel auditLevelModel = getDataDao.getAuditLevelByNowNodeEst(nowProcess);
            //获取审核单据表
            AccountingProjectModel auditOrder = getDataDao.getEstAuditOrderByBllId(order.getId());
            if ("部长级".equals(auditLevelModel.getAppLevelName())) {
                auditOrder.setApprover(auditLevelModel.getName());
                getDataDao.updateSheetDetailByPrimaryKey(auditOrder);
                order.setApproverUid(auditLevelModel.getUid());
                order.setApprovalDate(currentTime);
            } else if ("科长级".equals(auditLevelModel.getAppLevelName())) {
                auditOrder.setReviewer(auditLevelModel.getName());
                getDataDao.updateSheetDetailByPrimaryKey(auditOrder);
                order.setReviewerUid(auditLevelModel.getUid());
            }
            getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);

            //循环判断 当前的账号所在的流程节点；
            User user = ShiroUtils.getUser();
            List<AuditProcessModel> nowUserNodeInfo = getDataDao.findEstAppNodeInfoByUserId(user.getId());
            /**
             * 审批状态为2时；代表通过
             */
            if (param.getAppStatus() == 2) {
                /**
                 * 下一个节点=0 就是当前是最后的节点了，需要修改业务主表的状态值
                 */
                if (nowProcess.getStart() == 0) {
                    //1.1·当前是否是最后一个节点
                    //1.1.1·修改业务主表的状态值

                    /**
                     * bus_accounting_task submit_status: 1=未提交，2=待审核，3=审核通过，100=审核不通过
                     */
                    order.setSubmitStatus(3);
                    getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);
                    Task task = getDataDao.getTaskByPrimaryKey(order.getTaskId());
                    task.setEnddate(currentTime);
                    task.setTstatus(3);
                    getDataDao.updateTaskInfoByPrimaryKey(task);
                } else {
                    //1.2·找到下一个节点、下下个节点、审批人
                    List<AuditProcessModel> appList = getDataDao.findAppNodeInfo(nowUserNodeInfo.get(0).getOrderNo());
                    /**
                     * 根据我当前登录的账号，和流程配置的级别，找到那个人、
                     */
                    AuditProcessModel addAppInfo = new AuditProcessModel();

                    int pid = getDataDao.getNowLevelByUserId(user.getId());
                    /**
                     * 执行递归查询
                     */
                    addAppInfo.setVerifier(getPid(appList.get(0).getPost(), pid));
                    addAppInfo.setNowNode(appList.get(0).getId());
                    addAppInfo.setOrderNo(appList.get(0).getOrderNo());

                    if (appList != null && appList.size() >= 2) {
                        addAppInfo.setStart(appList.get(1).getId());
                    } else {
                        addAppInfo.setStart(0);
                    }
                    //下一个节点的，上一个节点是现在的id
                    addAppInfo.setComp(nowProcess.getNowNode());
                    addAppInfo.setCode("GS001");
                    addAppInfo.setSheetId(nowProcess.getSheetId());
                    addAppInfo.setAppStatus(1);
                    getDataDao.insertVerifyProcess(addAppInfo);
                }
                logService.saveLog("概算清单审核", ShiroUtils.getUser().getName() + "审核通过了" + order.getFounder() + "创建的项目号为" + order.getProCode() + "的核算清单！");
            } else {
                //2·NG+意见
                //2.1·存储当前的状态+结果
                if (nowProcess.getComp() == 0) {
                    //2.2.1·如果上一个是提交的话，修改业务主表的状态值
                    /**
                     * bus_accounting_task submit_status: 1=未提交，2=待审核，3=审核通过，100=审核不通过
                     */
                    order.setSubmitStatus(100);
                    getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);
                } else {
                    //2.2·找到上一个节点，生成下一个节点、审批人//
                    /**
                     * 根据我当前审批记录，找到我上一个临近的、
                     */
                    AuditProcessModel addAppInfo = getDataDao.findNextUserByNgInfo(param.getId());
                    addAppInfo.setAppStatus(1);
                    getDataDao.insertVerifyProcess(addAppInfo);
                    logService.saveLog("概算清单审核", ShiroUtils.getUser().getName() + "驳回了" + order.getFounder() + "创建的项目号为" + order.getProCode() + "的核算清单！");
                }
            }
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("审核成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getLocalizedMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("审核失败！");
        }
        return jsonResult;
    }
    /**
     * 递归：直到找到审批级别的上级人员id为止
     *
     * @param post
     * @param pid
     * @return
     */
    private int getPid(int post, int pid) {
        int userId = 0;
        AuditProcessModel nextModel = getDataDao.findNextLevelUserByPId(pid);
        if (nextModel != null) {
            if (nextModel.getPost() == post) {
                userId = nextModel.getSubmitUser();
            } else {
                getPid(post, nextModel.getParentId());
            }
        }
        return userId;
    }

    /**
     * queryList 根据查询条件检索概算查询列表
     *
     * @param param 查询条件
     * @return AccountingProjectModel 查询结果
     * @author 徐一贺
     * @date 2020/9/15 9:43
     * @version 1.0
     */
    public List<AccountingProjectModel> queryList(AccountingProjectModel param) {
        param.setCurrentUserId(ShiroUtils.getUserId());
        return estimateDao.findEstimatingProjectListByCriteriaFroQueryList(param);
    }
}
